/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Model.City;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author Admin
 */
public class CityHelper {

    Session session;

    public CityHelper() {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
    }
    
    public List<City> getAllCity(){
        List<City> lstCity = null;
        try {
            org.hibernate.Transaction tx = this.session.beginTransaction();
            Query q = this.session.createQuery("from City");
            lstCity = (List<City>)q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lstCity;
    }
    
    public void updateCity(City c){
        try {
            org.hibernate.Transaction tx = this.session.beginTransaction();
            this.session.save(c);
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
     public void deleteCity(City c){
        try {
            org.hibernate.Transaction tx = this.session.beginTransaction();
            this.session.delete(c);
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
